package com.org.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.org.IbatisBaseDao;
import com.org.dao.IAddressDao;
import com.org.model.Address;

/**
 * @Author:liangjilong
 * @Date:2014-1-15
 * @Email:jilongliang@sina.com
 * @Version:1.0
 * @Descript:
 */

@Component
@SuppressWarnings("all")
public class AddressDaoImpl extends IbatisBaseDao implements IAddressDao {
	
	
	public Address getReceiptAddressInfoById(String receiptAddId)  {
		try {
			Map param = new HashMap();
			param.put("receiptAddId", receiptAddId);
			return (Address) sqlMapClient.queryForObject("getAddressInfoByBueryId", param);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public Map getReceiptAddressListByBuyerId(Map params)  {
		try {
			Map map = new HashMap();
			Integer total = (Integer) sqlMapClient.queryForObject("getBuyerReceiptAddressCount", params);
			List list = sqlMapClient.queryForList("getBuyerReceiptAddressList", params);
			map.put("total", total);
			map.put("list", list);
			return map;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void deleteReceiptAddress(String primaryKey)  {
		try {
			sqlMapClient.delete("deleteReceiptAddress", primaryKey);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void addReceiptAddress(Address entity)  {
		try {
			sqlMapClient.insert("addReceiptAddress", entity);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void updateReceiptAddress(Address entity)  {
		try {
			sqlMapClient.update("updateReceiptAddress", entity);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public List<Address> getAddressByBuyerId(String buyerId)  {

		try {
			Map map = new HashMap();
			map.put("buyerId", buyerId);
			return (List<Address>) sqlMapClient.queryForList("findAddressByBuyerId", map);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
